package cn.tedu.zhyl.nurseManager.service.impl;

import cn.tedu.zhyl.base.response.PageResponse;
import cn.tedu.zhyl.base.utils.AuthContext;
import cn.tedu.zhyl.nurseManager.mapper.NurseProjectMapper;
import cn.tedu.zhyl.nurseManager.pojo.dto.NurseProjectQuery;
import cn.tedu.zhyl.nurseManager.pojo.dto.NurseProjectSaveParam;
import cn.tedu.zhyl.nurseManager.pojo.entity.NurseProject;
import cn.tedu.zhyl.nurseManager.pojo.vo.NurseProjectVO;
import cn.tedu.zhyl.nurseManager.pojo.vo.NursingItemVO;
import cn.tedu.zhyl.nurseManager.service.NurseProjectService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class NurseProjectServiceImpl implements NurseProjectService {
    @Autowired
    NurseProjectMapper nurseProjectMapper;

    @Override
    public PageResponse<NurseProjectVO> select(NurseProjectQuery nurseProjectQuery,Integer page,Integer limit) {
        PageHelper.startPage(page,limit);
        log.debug("查询护理项目业务:nurseProjectQuery={}", nurseProjectQuery);
        List<NurseProjectVO> list = nurseProjectMapper.select(nurseProjectQuery);
        return PageResponse.of(new PageInfo<>(list));
    }

    @Override
    public void save(NurseProjectSaveParam nurseProjectSaveParam) {
        NurseProject nurseProject = new NurseProject();
        BeanUtils.copyProperties(nurseProjectSaveParam,nurseProject);
        Long userId = AuthContext.get().getId();
        if (nurseProject.getId() == null){
            nurseProject.setCreateBy(userId);
            nurseProjectMapper.insert(nurseProject);
        }else {
            nurseProject.setUpdateBy(userId);
            nurseProjectMapper.update(nurseProject);

        }
    }

    @Override
    public void updateStatus(String status,Long id) {
        NurseProject nurseProject=new NurseProject();
        nurseProject.setStatus(status);
        nurseProject.setId(id);
        nurseProjectMapper.update(nurseProject);
    }

    @Override
    public void delete(Long id) {
        nurseProjectMapper.deleteById(id);
    }

    @Override
    public List<NursingItemVO> getList() {
        return nurseProjectMapper.getList();
    }
}
